package lagou.homework.lagou_homework_rocketmq.repository;

import lagou.homework.lagou_homework_rocketmq.entity.Seckill;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface SeckillRepository extends JpaRepository<Seckill,String> {

    @Query(nativeQuery = true,value = "select * from seckill where seckill.startTime<=now() and seckill.endTime>=now()")
    public List<Seckill> loadSeckillList();

    @Query(nativeQuery = true,value = "select * from seckill where seckill.endTime<now() and status != 2")
    public List<Seckill> loadExpireSeckillList();

    @Query(nativeQuery = true,value = "update seckill set status=? where secKillId=?")
    @Modifying
    @Transactional
    public int updateStatus( int status,String killId);



}
